<?php
set_time_limit(0);
include 'dom.php';
include '../config/config.php';
$maxId=2; //max=29
$leiId=array(1=>1,2=>3,3=>5,4=>7,5=>9,6=>11,7=>13,8=>15,9=>17,
    10=>19,11=>21,12=>23,13=>25,14=>27,15=>29,16=>31,17=>33
);
$id=count($leiId); 

if (isset($_GET['id'])){
    $id=$_GET['id'];
}

$url='http://localhost/app/spider/qq/'.$id.'.php';
$html = file_get_html($url);


$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
if (1 == $id){
    $query = $mysqli->query("truncate cai_list");
}
foreach($html->find('ul.category-list li.category-item') as $pcName) {
    $getA=$pcName->find('a', 0);
    $href=$getA->href;
    $title=$pcName->find('h2.category-name', 0)->plaintext;
    $parseUrl=explode('_', $href);
    $flagid=str_replace('.html', '', $parseUrl[count($parseUrl)-1]);
     
    $sql="select id from cai_list where flagid='".$flagid."' and cateid='".$leiId[$id]."'  limit 0,1 ";
    $query = $mysqli->query($sql);
    if($query->num_rows>0){
    }else{
        $sql="insert into cai_list(title,link,flagid,cateid) values('".$title."','".$href."','".$flagid."','".$leiId[$id]."')";
        $mysqli->query($sql);
    }

}

echo 'done'.$id.'.......'.$id;
echo "<br />";

echo "&nbsp;&nbsp;&nbsp;";
echo '<a href="?id='.($id+1).'">next</a>';

sleep(1);
if($maxId == $id){
    exit;
}
?>
<script>
window.setTimeout(function(){
	  // window.location.href="?id=<?php echo ($id+1); ?>";
	}, 1000);
</script>

 
 

